//
// Created by ZLY on 2025/5/11.
//

#include "weapon.h"
#include "../core/actor.h"
#include "stats.h"
#include "../core/scene.h"
#include "../world/spell.h"

void Weapon::update(float dt) {
    Object::update(dt);
    cooldown_timer_ += dt;
}

void Weapon::attack(glm::vec2 position, Spell *spell) {
    if (!spell) {
        return;
    }
    parent_->getStats()->useMana(mana_cost_);
    cooldown_timer_ = 0;
    spell->setPosition(position);
    game_.getCurrentScene()->safeAddChild(spell);
}


bool Weapon::canAttack() const {
    if (cooldown_timer_ >= cooldown_) {
        if (parent_->getStats()->canUseMana(mana_cost_)) {
            return true;
        }
    }
    return false;
}
